<?php

class Database {

    // Function to the database and tables and fill them with the default data
    function create_database($data)
    {
        // Connect to the database
        $mysqli = new mysqli($data['hn'],$data['un'],$data['pw'],'');

        // Check for errors
        if(mysqli_connect_errno())
            return false;

        // Create the prepared statement
        $mysqli->query("CREATE DATABASE IF NOT EXISTS " . $data['db']);

        // Close the connection
        $mysqli->close();

        // Connect to the database
        $mysqli = new mysqli($data['hn'],$data['un'],$data['pw'],$data['db']);

        $sql = file_get_contents('assets/install.sql');

        $sqls = explode(';', $sql);

        for($i = 0; $i < count($sqls) - 1; $i++)
        {
            $mysqli->query($sqls[$i]);
        }

        // Close the connection
        $mysqli->close();

        return true;
    }

}
?>